const {
  http
} = require("../../../../utils/apiutils");
const util = require("../../../../utils/util");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    dataList: [],
    pageNo: 1,
    total: 0,
    dataList1: [],
    pageNo1: 1,
    total1: 0,
    dataList2: [],
    pageNo2: 1,
    total2: 0,
    dataList3: [],
    pageNo3: 1,
    total3: 0,
    dataList4: [],
    pageNo4: 1,
    total4: 0,
    dataList5: [],
    pageNo5: 1,
    total5: 0,
    message:"",
    showsf: false,
    sum: {
      nviteSalarySum: 0,
      salarySum: 0,
      workSalarySum: 0
    },
    showd:false,
		dataParams: {},
		jlsu: false,
		showd1: false,
		showArr: [],
		jzindex: 0,
		suid:0

  },
  onChange(event) {
    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
    if (event.detail.name == 0) {
      this.data.pageNo = 1;
      this.getworkList();
    } else if (event.detail.name == 1) {
      this.data.pageNo1 = 1;
      this.getinviteList();
    } else if (event.detail.name == 2) {
      this.data.pageNo2 = 1;
      this.getinviteList1();
    } else if (event.detail.name == 3) {
      this.data.pageNo3 = 1;
      this.getinviteList3();
    } else if (event.detail.name == 4) {
      this.data.pageNo4 = 1;
      this.getinviteList4();
    } else if (event.detail.name == 5) {
      this.data.pageNo5 = 1;
      this.getinviteList5();
    }
  },

  onclickCell: function (e) {
    let index = e.currentTarget.dataset.index;
    if (index == 1) {
      wx.navigateTo({
        url: '/pages/me/pages/cashout/cashout',
      })
    } else if (index == 2) {
      wx.navigateTo({
        url: '/pages/me/pages/cashoutList/cashoutList',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  getinviteList1: function () {
    var data = {
      "pageNo": this.data.pageNo2, //手机号码
      "pageSize": "99999", //密码
      "type": 2,
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getinviteList(data,
      function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          var pageNo2 = res.data.current;
          var total2 = res.data.pages;
          var arr = res.data.records;
          if (pageNo2 == 1) {
            that.setData({
              dataList2: arr,
              pageNo2,
              total2
            })
          } else if (pageNo2 <= total2) {

            that.setData({
              dataList2: [...that.data.dataList2, ...arr],
              pageNo2,
              total2
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  getinviteList3: function () {
    var data = {
      "pageNo": this.data.pageNo3, //手机号码
      "pageSize": "99999", //密码
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getRenwuMoney(data,
      function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          var pageNo3 = res.data.current;
          var total3 = res.data.pages;
          var arr = res.data.records;
          if (pageNo3 == 1) {
            that.setData({
              dataList3: arr,
              pageNo3,
              total3
            })
          } else if (pageNo3 <= total3) {

            that.setData({
              dataList3: [...that.data.dataList3, ...arr],
              pageNo3,
              total3
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  getinviteList4: function () {
    var data = {
      "pageNo": this.data.pageNo4, //手机号码
      "pageSize": "99999", //密码
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.queryMySalaryPageList(data,
      function (res) {
        wx.hideLoading()
        if (res.status == 200) {
          var pageNo4 = res.obj.current;
          var total4 = res.obj.pages;
			var arr = res.obj.records;
			arr.map(item => { 
				if (item.details.length > 0) { 
					item.details.forEach(ele => {
						let time   = ele.updateTime.replace(/-/g, '/');
						ele.updateTime = util.getHHMM(time);
					})
				}
			})
          if (pageNo4 == 1) {
            that.setData({
              dataList4: arr,
              pageNo4,
              total4
            })
          } else if (pageNo4 <= total4) {

            that.setData({
              dataList4: [...that.data.dataList4, ...arr],
              pageNo4,
              total4
            })
          }
        } else {
          wx.showToast({
            title: res.message||res.msg,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  getinviteList5: function () {
    var data = {
      "pageNo": this.data.pageNo4, //手机号码
      "pageSize": "99999", //密码
    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.queryMyList(data,
      function (res) {
        wx.hideLoading()
        if (res.status == 200) {
          var pageNo5 = res.obj.current;
          var total5 = res.obj.pages;
			var arr = res.obj.records;
          if (pageNo5 == 1) {
            that.setData({
              dataList5: arr,
              pageNo5,
              total5
            })
          } else if (pageNo5 <= total5) {

            that.setData({
              dataList5: [...that.data.dataList5, ...arr],
              pageNo5,
              total5
            })
          }
        } else {
          wx.showToast({
            title: res.message||res.msg,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  onclickSure: function (e) {
    // 4 无意义  5申诉
    let item = e.currentTarget.dataset.item;
    this.sumbitSure(item.id, 4);
  },
  onClose:function(){
  this.setData({
    message:"",
	  showsf: false,
	  jlsu:false
  })
  },
  onclickconfirm:function(){
    // 4 无意义  5申诉
    if(this.data.message.length>3)
    {
      this.sumbitSure(this.data.cid,5,this.data.message)
    }
    else
    {
      wx.showToast({
        title: '请详细描述原因后提交',
        icon:"none",
      })

    }
  },
  bindinputm:function(e) {
    this.data.message = e.detail;
  },
  onclickSure1: function (e) {
    let item = e.currentTarget.dataset.item;   
    this.setData({
      showsf: true,
      message:"",
      cid:item.id
    })

  },
  sumbitSure: function (id, type, reason) {
    var data = {
      "type": type,
    }
    if (type == 5) {
      data["reason"] = reason;
    }
    var that = this; 
    wx.showLoading({
      title: '加载中...',
    })
    console.log("--提交信息--",id,data)
    http.confirmSy(data, id,
      function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          wx.showToast({
            title: '提交成功',
            icon: "none",
          })
          that.data.pageNo = 1;
          that.getsalarySum()
          that.getworkList()
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  closeShowd(){
    this.setData({
		showd: false,
		showd1:false
    })
  },
  getinviteList: function () {
    var data = {
      "pageNo": this.data.pageNo1, //手机号码
      "pageSize": "9999", //密码
      type: 1,
    }
    var that = this;
    http.getinviteList(data,
      function (res) {
        if (res.code == 0) {
          var pageNo1 = res.data.current;
          var total1 = res.data.pages;
          var arr = res.data.records;
          if (pageNo1 == 1) {
            that.setData({
              dataList1: arr,
              pageNo1,
              total1
            })
          } else if (pageNo1 <= total1) {

            that.setData({
              dataList1: [...that.data.dataList1, ...arr],
              pageNo1,
              total1
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })
  },
  getworkList: function () {
    var data = {
      "pageNo": this.data.pageNo, //手机号码
      "pageSize": "9999" //密码
    }
    var that = this;

    http.getworkList(data,
      function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          var pageNo = res.data.current;
          var total = res.data.pages;
          var arr = res.data.records;
          if (pageNo == 1) {
            that.setData({
              dataList: arr,
              pageNo,
              total
            })
          } else if (pageNo <= total) {

            that.setData({
              dataList: [...that.data.dataList, ...arr],
              pageNo,
              total
            })
          }
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  getsalarySum: function () {

    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getsalarySum({},
      function (res) {
        wx.hideLoading()
        console.log("------总是收益--", res.data);
        if (res.code == 0) {
          that.setData({
            sum: res.data
          })
        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getsalarySum()
    if (this.data.active == 0) {
      this.getworkList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var shareObj = {
      title: "分享岗位", // 默认是小程序的名称(可以写slogan等)
      path: getApp().globalData.userInfo.inviteCode?'/pages/index/index?code='+getApp().globalData.userInfo.inviteCode:'/pages/index/index', // 
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
        }
      }
    }
    console.log("------------", shareObj);
    // 返回shareObj
    return shareObj;
  },
  showdtl(e){
    let obj = e.currentTarget.dataset.item;
    if (obj.extra) { 
      obj.sum = 0;
      let arr = JSON.parse(obj.extra);
      arr.map(item => { 
        obj.sum+=item.value/100
      })
      obj.extra=arr
    }
    this.setData({
      dataParams:obj,
      showd:true
    })
	},
	showindex(e) { 
		let index = e.currentTarget.dataset.index;
		let arr = [...this.data.showArr];
		let a = arr.indexOf(index);
		if (a > -1) {
			arr.splice(a, 1)
		} else { 
			arr.push(index)
		}
		this.setData({
			showArr:arr
		})
	},
	appeal(e) { 
		let id = e.currentTarget.dataset.id;
		this.setData({
			suid: id,
			jlsu:true
		})
	},
	appeal1() { 
		http.appeal({
			id: this.data.suid,
			remark:this.data.message
		}, res => {
			wx.showToast({
				title: res.message,
				icon:"none"
			})
			this.data.pageNo4 = 1;
			this.getinviteList4();
		 }, err => { 

		})
	},
	showdtl1(e) { 
		let index = e.currentTarget.dataset.index;
		this.setData({
			jzindex: index,
			showd1:true
		})
	}
	
})